package com.alquimia.identityaccess.application.events.user;

import com.alquimia.identityaccess.application.events.UpdatedEvent;
import com.alquimia.identityaccess.domain.model.User;

/**
 * Created by Ivo on 16/07/2014.
 */
public class UserEmailAddressUpdatedEvent extends UpdatedEvent {

    private String userId;
    private String emailAddress;

    public UserEmailAddressUpdatedEvent(User aUser) {
        super();

        this.initializeFrom(aUser);
    }

    public UserEmailAddressUpdatedEvent(String aUserId) {
        super();

        this.userId = aUserId;
    }

    public String getEmailAddress() {
        return emailAddress;
    }

    public String getUserId() {
        return userId;
    }

    private void initializeFrom(User aUser) {
        this.emailAddress = aUser.person().emailAddress().address();
        this.userId = aUser.userId().id().toString();
    }

    public static UserEmailAddressUpdatedEvent notFound(String aUserId) {
        UserEmailAddressUpdatedEvent userEmailAddressUpdatedEvent = new UserEmailAddressUpdatedEvent(aUserId);
        userEmailAddressUpdatedEvent.entityFound = false;
        return userEmailAddressUpdatedEvent;
    }
}
